package com.wilcom.system.common;
import java.util.List;
public class Page<T> {
    // 页大小
    private int pageSize;
    // 页码
    private int pageNum;
    // 总数据量
    private int totalSize;
    // 总页数
    private int totalCount;
    // 当前页
    private int preNum;
    // 下一页
    private int nextNum;
    // 当前首页
    private int startNavNum;
    // 当前尾页
    private int endNavNum;
    
    // 具体数据
    private List<T> books;

    public Page(int pageSize, int pageNum, int totalSize, List<T> books) {
        this.pageSize = pageSize;
        this.pageNum = pageNum;
        this.totalSize = totalSize;
        this.books = books;

        this.totalCount = (int) Math.ceil(totalSize/(pageSize*1.0));

        this.preNum=pageNum-1<1?1:pageNum-1;
        this.nextNum=pageNum+1>totalCount?totalSize:pageNum+1;

        this.startNavNum = pageNum-3;
        this.endNavNum =pageNum+2;

        if(startNavNum<1){
           this.startNavNum=1;
           this.endNavNum = startNavNum+5>totalCount?totalCount:startNavNum+5;
        }

        if(endNavNum>totalCount){
            this.endNavNum=totalCount;
            this.startNavNum = endNavNum-5<1?1:endNavNum-5;
        }
    }
}

